<?php
/**
 * Created by PhpStorm.
 * User: songs
 * Date: 2019/10/12
 * Time: 10:13
 */

namespace App\admin\TableView;


use App\admin\TableView\BaseClass\BaseViewList;
use App\Jobs\Fun;
use App\Models\Admin\ApilistModel;
use App\Models\Main\MsgSysModel;
use App\Models\MoneyBilModel;
use App\Models\UploadPicModel;

class FilePicView extends BaseViewList
{

    public function get_model()
    {

        return new UploadPicModel();
    }

    public $show_add = false; ///显示添加按钮
    ///     /**
    //     * 是否显示删除按钮
    //     */
    /**
     * 是否显示删除按钮
     */
    public $show_delete = false;
    public $topTitle = '图片管理';
    public $PageSize = 10;

    public $breadcrumb = '<li><a href="/mcadmin">Home</a></li>
        <li><a href="javascript:;">图片管理</a></li>
        ';

    public $html = '';


    //  public $show_add = false; ///显示添加按钮

    /**
     * 获取表格的唯一名字
     */
    public function getName()
    {
        return 'UploadPicModel';
    }


    /**
     * 需要继承,然后定义每行需要显示的数据格式
     */
    public function Labels()
    {
        return array(
            //   BaseViewList::Button_checkbox=>[],
            'md5' => 40,
            'ext'=>50,
            'pic'=>50,
            'time'=>50,
           /* BaseViewList::Button_control => [

                BaseViewList::Button_Edit,
                BaseViewList::Button_Delete

            ]*/
        );
    }

    /**
     * 对话框中的各个字段
     */
    public function dialog()
    {
        return array(
        );
    }

    /**
     * 方便继承,多一层过滤
     */
    public function ModelTohtml($key, $model)
    {

        if($key=='time'){
            return Fun::date($model->$key);
        }
        if($key=='pic'){
            $Small=Fun::pImg(
                $model->path.$model->md5.UploadPicModel::TypeSmall.'.'.$model->ext
            );
            $big=Fun::pImg(
                $model->path.$model->md5.UploadPicModel::TypeBig.'.'.$model->ext
            );
            return '<a target="_blank" href="'.$big.'">'.$this->toImg($Small).'</a>';
            ///return $this->toImg();
        }

        return parent::ModelTohtml($key, $model);
    }

    /**
     * 返回查询的条件
     */
    public function find() {
        $find = $this->get_model()->where([]);

        if (isset($_GET['submit']) && $_GET['submit'] == 'true') {
            $this->where($find);
        }

        $find->orderBy('time','DESC');
        return $find;
    }

}